package com.bdqn;

import com.pojo.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

public class Sjlx2 {
    public static void main(String[] args) {
        try {
            Person person=new Person();
            Class clz=Class.forName("com.pojo.Person");
            Object obj=clz.newInstance();
            Field name=clz.getDeclaredField("name");
            name.setAccessible(true);
            System.out.println("赋值前的name:"+name.get(person));
            name.set(person,"New Person");
            System.out.println("赋值后的name:"+name.get(person));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }
}
